//
//  OrdersTableViewController.m
//  AppointmentForCar
//
//  Created by Herron on 16/10/3.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "OrdersTableViewController.h"
#import "OrderCell.h"
#import "HomeViewModel.h"
@interface OrdersTableViewController ()

@property (nonatomic , strong) HomeViewModel * model;
@end

@implementation OrdersTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"历史行程";
    
    [self.tableView registerNib:[UINib nibWithNibName:@"OrderCell" bundle:nil] forCellReuseIdentifier:@"OrderCellID"];
//    [self.tableView setRowHeight:140];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.estimatedRowHeight = 140;
//    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
    [self.model getDriverHistoricalRecordWithId:[UserAccountManager shareUserManager].user.driverId complete:^(id error) {
        [self.tableView reloadData];
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.model.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderCellID" forIndexPath:indexPath];
    [cell setupCell:self.model.dataArray[indexPath.row]];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}

- (HomeViewModel *)model {
    if(!_model) {
        _model = [[HomeViewModel alloc] init];
    }
    return _model;
}

@end
